package com.mastercard.labs

import static org.junit.Assert.*

import grails.test.mixin.support.*


class MerchantServicesTest {

	def merchantService
	def merchant, category, country
	
	void testGetMerchantById() {
		println("-------- testGetMerchantById ----------")
		def mer = merchantService.getMerchantById(1)
		assert mer.name != null && !mer.name.trim().equals("")
	}
	
    void testSearchMerchantByCondition() {
		println("-------- testSearchMerchantByCondition ----------")
		def list = merchantService.searchMerchantByCondition("NUS", null, null, null)
		assert list.size() > 0
		
		if(list.size() > 0){
			def mer = list.get(0)
			assert mer.country.name == "Singapore"
		}
    }
	
	void testSearchMerchantForDashboard() {
		println("-------- testSearchMerchantForDashboard ----------")
		def list = merchantService.searchMerchantForDashboard()
		assert list.size() == 5
		
		if(list.size() > 0){
			def mer = list.get(0)
			assert mer != null && mer.name != null && !mer.name.trim().equals("")
		}
	}
	
	void testSaveMerchant() {
		println("-------- testSaveMerchant ----------")
		
		def mer = merchantService.getMerchantById(1)
		mer.contact = "12345678"
		merchantService.saveMerchant(mer)
		
		def tmp = merchantService.getMerchantById(1)
		assert tmp.contact == "12345678"
	}
}
